<template>
  <div>
    <header>
      <van-nav-bar title="添加地址">
        <template #left>
          <van-icon
            name="arrow-left"
            size="26"
            color="black"
            @click="$router.back()"
          />
        </template>
      </van-nav-bar>
    </header>
    <van-address-edit
      :area-list="areaList"
      :address-info	="AddressInfo"
      show-set-default
      save-button-text='添加'
      @save="onSave"
    />
  </div>
</template>

<script>
import { areaList } from '@vant/area-data';
import { addAddress } from '../api/user';
import Vue from "vue";
import { AddressEdit ,Area ,Toast } from "vant";

Vue.use(AddressEdit);
Vue.use(Area );
Vue.use(Toast  );

export default {
  data() {
    return {
        areaList,
        AddressInfo:{
          
        }
    };
  },
  methods: {
    onSave(content) {
      console.log(content);
      addAddress({userid:localStorage.getItem("userid"),name:content.name,tel:content.tel,province:content.province,city:content.city,county:content.county,addressDetail:content.addressDetail,isDefault:content.isDefault}).then(res=>{
        console.log(res);
        if(res.data.code==200){
            Toast('添加成功');
            setTimeout(()=>{
                this.$router.back()
            },1000)
        }
      })
    },
  },
};
</script>

<style scoped>
.nextbtn {
  width: 80%;
  margin: 0.1rem auto;
}
</style>